#include "comm.hpp"

int main()
{
    cout<<"I am Client!"<<endl;
    int wfd = open(PATH, O_WRONLY);
    if (wfd < 0)
    {
        cerr << "open file failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
        return 1;
    }
    cout << "open file success" << endl;
    // 向命名管道写入内容(输入字符串避免出现空白字符使用getline())
    string str;
    while (true)
    {
        cout << "Please Enter Your Message# ";
        getline(cin,str);
        ssize_t n=write(wfd,str.c_str(),str.size());
        if(str=="quit")
        {
            //此处采用"quit"构造string类的匿名对象,然后使用匿名对象与str进行比较
            break;
        }
        if(n<0)
        {
            //写入失败,返回-1
            cerr << "write failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
            break;
        }
    }
    return 0;
}